//
//  DYZCustomAppearanceColourController.m
//  DYZCars
//
//  Created by 白白龙腾 on 16/8/19.
//  Copyright © 2016年 MF. All rights reserved.
//

#import "DYZCustomAppearanceColourController.h"
#import "DYZCustomAppearanceColourCell.h"
#import "DYZInsideColourController.h"
#import "DSHTTPClient.h"
static NSString *customAppearanceCellid = @"customAppearanceCellid";
@interface DYZCustomAppearanceColourController ()

@property(nonatomic,strong)NSArray *dataArray;

@end

@implementation DYZCustomAppearanceColourController

- (void)viewDidLoad {
    [super viewDidLoad];
    //禁用弹性效果
    self.tableView.bounces = NO;
    //隐藏没有内容的cell的下划线
    self.tableView.tableFooterView = [[UIView alloc]init];
    //左侧按钮
    UIButton *aButton = [[UIButton alloc]init];
    [aButton setImage:[UIImage imageNamed:@"btn_backItem"] forState:UIControlStateNormal];
    [aButton sizeToFit];
    //添加点击事件
    [aButton addTarget:self action:@selector(aButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:aButton];
    self.navigationItem.leftBarButtonItem = item;
    
    //右侧保存按钮
    UIButton *rightBtn = [[UIButton alloc]init];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightBtn sizeToFit];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    //给你右侧按钮添加点击事件
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    //设置navitem的文字
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor blackColor]];
    [customLab setText:@"自定义外观颜色"];
    customLab.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = customLab;
    
    //注册单元格
    [self.tableView registerNib:[UINib nibWithNibName:@"DYZCustomAppearanceColourCell" bundle:nil] forCellReuseIdentifier:customAppearanceCellid];
    
}

//解析外观颜色
- (void)color{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    [param setValue:@"1" forKey:@"accountid"];
    
    
    [DSHTTPClient postUrlString:@"http://iosapi.itcast.cn/car/searchcolor.json.php" withParam:param withSuccessBlock:^(NSDictionary * data) {
        NSMutableArray *array = [NSMutableArray array];
        
        NSDictionary *dict = [data objectForKey:@"data"];
        
        NSArray *arr = [dict objectForKey:@"list"];
        
        for (NSDictionary *dict1 in arr) {
            
            NSString *str = [dict1 objectForKey:@"outsideColor"];
            
            [array addObject:str];
        }
        
        self.dataArray = array;
        
        [self.tableView reloadData];
        
    } withFailedBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } withErrorBlock:^(NSString *message) {
        NSLog(@"%@",message);
    }];
}

//点击aButton
- (void)aButtonClick{
    [self.navigationController popViewControllerAnimated:YES];
}

//点击rightButton
- (void)rightBtnClick{
    DYZInsideColourController *incon = [[DYZInsideColourController alloc]init];
    [self.navigationController pushViewController:incon animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DYZCustomAppearanceColourCell *cell = [tableView dequeueReusableCellWithIdentifier:customAppearanceCellid forIndexPath:indexPath];
    return cell;
}

//设置cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

@end
